@isTest private class CreateNewDiscussionForumTest
{
    static testMethod void myUnitTest() 
    {
        try
        {
            GenerateEnvironmentTest.gen();
            Test.startTest();
            
            System.currentPageReference().getParameters().put('id', GenerateEnvironmentTest.newDiscussionForum.Id);
            
            update GenerateEnvironmentTest.newDiscussionForum;
            
            
            CreateNewDiscussionForumController df = new CreateNewDiscussionForumController();

                         
            DiscussionForum__c t = GenerateEnvironmentTest.newDiscussionForum;
            df.setDiscussion(t);
            t = df.getDiscussion();
            df.getNewProfile();
            df.setdocument(new Attachment(Name = 'Name', Body = Crypto.generateMac('HMacSHA1', Blob.valueOf('String'), Blob.valueOf('String'))));
            df.getdocument();
            CreateNewDiscussionForumController.discussionProfile openClose = new CreateNewDiscussionForumController.discussionProfile();
          
            // Covering all level of access
            openClose = df.getNewProfile();
            openClose.discussionOpenOrClosed = 'open';
            df.setNewProfile( openClose );
            df.saveDiscussionForum();
            
            openClose = df.getNewProfile();
            openClose.discussionOpenOrClosed = 'close';
            df.setNewProfile( openClose );
            //df.saveDiscussionForum();
            
            df.setdocument(new Attachment(Name = '', Body = Crypto.generateMac('HMacSHA1', Blob.valueOf('String'), Blob.valueOf('String'))));
            openClose = df.getNewProfile();
            openClose.discussionOpenOrClosed = 'private';
            df.setNewProfile( openClose );
                        
            Test.stopTest();
        }
        catch(Exception e)
        {
            throw e;
        }
    }
    
    /* Member list test */
    

    public static String idTeam = System.currentPageReference().getParameters().get('id');
    public static Boolean sortByDesc = false;
    
    public static String sortBy = 'User__r.Name';
    User newUser = [select id from User where id !=: UserInfo.getUserId() limit 1];
    
    public static testMethod void testTeam() {
        try{
            GenerateEnvironmentTest.gen();
            Test.startTest();

            System.currentPageReference().getParameters().put('id',GenerateEnvironmentTest.newDiscussionforum.Id );
            CreateNewDiscussionForumController df = new CreateNewDiscussionForumController();
          
            df.theDiscussion = GenerateEnvironmentTest.newDiscussionForum;
            
            df.getNamespace();
            
            // Team Inner Class
            CreateNewDiscussionForumController.Member member = new CreateNewDiscussionForumController.Member();
            
            member.setAlias('');
            member.setUsername('');
            member.setMemberImg(GenerateEnvironmentTest.newDiscussionMember.User__c);
            
            member.setTitle('');
            member.setProfile('');
            member.setName('');
            member.setUserId(GenerateEnvironmentTest.newDiscussionMember.User__c);
            member.setDiscussionMemberId(GenerateEnvironmentTest.newDiscussionMember.Id);
            member.setAdmin(true);

            member.getAlias();
            member.getUsername();
            member.getMemberImg();
            member.getTitle();
            member.getProfile();
            member.getName();
            member.getUserId();
            member.getDiscussionMemberId();
            member.getAdmin();
            
            // Pagination Methods
            df.genCntPagination();
            df.nextPage();
            df.prevPage();
            df.getCurrentPagination();
            df.getNumberOfItemsToShow();
            df.getFirstRow();
            //df.getLastItem();
            //df.getTotalItemsNumber();
            
            
            df.currentPagination = 1;
            Boolean b1 = df.getPrevPageLinkShow();
            Boolean b2 = df.getPrevPageShow();
            Boolean b3 = df.getNextPageLinkShow();
            Boolean b4 = df.getNextPageShow();
            
            df.currentPagination = 0;
            df.cntPagination = 0;
            b1 = df.getPrevPageLinkShow();
            b2 = df.getPrevPageShow();
            b3 = df.getNextPageLinkShow();
            b4 = df.getNextPageShow();
            
            // Methods without SOQL queries
            Attachment doc = new Attachment( Name = '', Body = Crypto.generateMac('HMacSHA1', Blob.valueOf('String'), Blob.valueOf('String' )));
         
            df.setdocument( doc );
            df.setUserId(GenerateEnvironmentTest.newUser.Id);
            df.getrowsCodeCoverage();
            df.showMembersList();
            df.setRowsCodeCoverage( 100 );
            df.isAdministrator();
            df.getEnabledMembersTab();
            df.getForums();
            df.getMembersList();
            df.getDiscussionForum();
            df.getValidSizePicture();
            df.getNoForums();
            df.setEnabledMembersTab('');
            df.getTabControl();
            //df.assignRemoveId();
            df.getDiscussionId();
            df.getUserPermissions();
            List<CreateNewDiscussionForumController.Member> mem = df.getMembers();
            df.getCntPagination();
             
            // Methods WITH SOQL queries
            df.getMostActiveUsers();
                        
            df.getMostActiveUsers();
            //df.saveAndRedirect();
            
           
            List<CreateNewdiscussionForumcontroller.DiscussionForums> dfs = new List<CreateNewdiscussionForumcontroller.DiscussionForums>();
            CreateNewdiscussionForumcontroller.DiscussionForums dfClass = new CreateNewdiscussionForumcontroller.DiscussionForums();
            dfClass.setNumberOfMessages( 10000.1 );
            dfs = df.getDiscussionForums( GenerateEnvironmentTest.newDiscussionMember.User__c );
           
            dfClass.getDiscussionName(); // 1 SOQL
            dfClass.getDiscussionDescription();
            dfClass.getNumberOfMessages();
            dfClass.getNumberOfThreads();
            dfClass.getLastPostMessage();
            dfClass.getImage();
            dfClass.lastPostInfoString( GenerateEnvironmentTest.newMessage.Id );
            System.currentPageReference().getParameters().put('delId',GenerateEnvironmentTest.newDiscussionMember.User__c);
            //df.assignRemoveId();// 1 SOQL 
            df.genMembers(); // 1 SOQL
            df.letter = 'A';
            df.genMembers(); // 1 SOQL
            
            System.currentPageReference().getParameters().put('ltr','true');
            df.genMembers(); // 1 SOQL
            
            // Methods WITH more than 1 SOQL query
            System.currentPageReference().getParameters().put('editId',GenerateEnvironmentTest.newUser.Id );
            df.assignEditId(); // 4 SOQL
            //df.editMemberAction();
            
            df.refresh();
                        
            //////////////////////////////
            //      92 SOQL AND 74%     //
            //////////////////////////////
            
            Test.stopTest();
        }
        catch(Exception e){
            throw e;
        }
    }
    
    /* Member list test2 */
    

    public static testMethod void testTeam2() 
    {
        try
        {
            GenerateEnvironmentTest.gen();
            Test.startTest();

            CreateNewDiscussionForumController df = new CreateNewDiscussionForumController();
            df.theDiscussion = GenerateEnvironmentTest.newDiscussionForum;

            // Methods with SOQL
            df.getDiscussionEditProfiles(); // 1 SOQL

              /*
            *Probing genPrifles() 
            */
            List<DiscussionProfile__c> profileList = [select Id from DiscussionProfile__c]; 
            if( profileList.size() > 0 )
                delete profileList;

            df.genProfiles();
            
            // Letters Inner Class
            CreateNewDiscussionForumController.Letters letter = new CreateNewDiscussionForumController.Letters();
            List<CreateNewDiscussionForumController.Letters> letters = df.getLetterFilter();
            letter.setLetter('');
            letter.getLetter();
            letter.setContainMembers(0);
            letter.getContainMembers();
            
            // ActiveUser inner class
            CreateNewDiscussionForumController.ActiveUser ac = new CreateNewDiscussionForumController.ActiveUser();
            ac.setCommentsCount( 10 );
            ac.getPicture();
            ac.getCommentsCount();
            ac.getName();
            ac.getId();
            
            Test.stopTest();
        }
        catch(Exception e)
        {
            throw e;
        }
    }
    
    public static testMethod void testTeam3() 
    {
        try
        {
            GenerateEnvironmentTest.gen();
            Test.startTest();

            CreateNewDiscussionForumController df = new CreateNewDiscussionForumController();
            df.theDiscussion = GenerateEnvironmentTest.newDiscussionForum;
            // Sort Methods
            df.getSortByDesc();

            df.sortByDesc = true;
                df.letter = 'A';
                    df.setSortBy('User__r.Name');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
    
                    df.setSortBy('User__r.Alias');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
                                
                    df.setSortBy('DiscussionProfile__r.Name');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
                    
                    df.setSortBy('User__r.Username');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL                    
                df.letter = null;
                    df.setSortBy('User__r.Name');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
    
                    df.setSortBy('User__r.Alias');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
                                
                    df.setSortBy('DiscussionProfile__r.Name');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
                    
                    df.setSortBy('User__r.Username');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL

            df.sortByDesc = false;
                df.letter = 'G';
                    df.setSortBy('User__r.Name');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
    
                    df.setSortBy('User__r.Alias');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
                                
                    df.setSortBy('DiscussionProfile__r.Name');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
                    
                    df.setSortBy('User__r.Username');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL                    
                df.letter = null;
                    df.setSortBy('User__r.Name');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
    
                    df.setSortBy('User__r.Alias');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
                                
                    df.setSortBy('DiscussionProfile__r.Name');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL
                    
                    df.setSortBy('User__r.Username');
                    df.getSortBy();
                    df.sortList(); // 1 SOQL

            Test.stopTest();
        }
        catch(Exception e)
        {
            throw e;
        }
    }
}